<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>已知⼀个数组序列，全部为正整数，找出其中任意两个数相差最⼤的组合</title>
</head>
<body>
  <script>
    var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    // 假设 arr[0] 是最大值 和 最小值
    var max = arr[0]
    var min = arr[0]
    var res = []
    for(let i = 0; i < arr.length; i++) {
      if(arr[i] > max){
        max = arr[i]
      }
      if(arr[i] < min) {
        min = arr[i]
      }
    }
    // 把最大值和最小值添加到 res 中
    res.push(max, min)
    console.log(res)
  </script>
</body>
</html>